package com.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mall.annotation.OperationLog;
import com.mall.db.domain.Coupons;
import com.mall.db.service.CouponsService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/system/cp")
public class couponsController extends BaseController<Coupons>{
    @Resource(name ="couponsService" )
    private CouponsService cps;

    @Override
    public Map<String, Object> find(Coupons coupons) {
        PageHelper.startPage(coupons.getPage(),coupons.getLimit());
        QueryWrapper<Coupons> qw = new QueryWrapper<>();
        List<Coupons> list = cps.list(qw);
        PageInfo<Coupons> page = new PageInfo<>(list,coupons.getLimit());
        return this.findMap(page.getList(), page.getTotal());

    }

    @Override
    @OperationLog(value = "优惠券删除",type = 3)
    public Map<String, Object> delete(Coupons coupons) {
        boolean b=cps.removeById(coupons);
        return this.iud("删除",b,coupons);
    }

    @Override
    @OperationLog(value = "优惠券更新",type = 3)
    public Map<String, Object> update(Coupons coupons) {
            boolean b=cps.updateById(coupons);
        return this.iud("更新",b,coupons);
    }
}
